package com.byx.chatclient.adapter;

import com.byx.chatclient.R;
import com.byx.chatclient.bean.SearchUserBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * SearchUserAdapter
 * 搜索好友列表适配器
 * @author Superb
 * @date 2021/4/26 21:10
 */
public class SearchUserAdapter extends BaseQuickAdapter<SearchUserBean, BaseViewHolder> {
    private static final int LAYOUT_RES_ID = R.layout.layout_search_user_item;
    private static final String SEX_MAN = "♂";
    private static final String SEX_WOMAN = "♀";

    public SearchUserAdapter(@Nullable List<SearchUserBean> data) {
        super(LAYOUT_RES_ID, data);
        init();
    }

    public SearchUserAdapter() {
        super(LAYOUT_RES_ID);
        init();
    }

    private void init() {
        addChildClickViewIds(R.id.btn_add_friend);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, SearchUserBean searchUserBean) {
        ((SimpleDraweeView) baseViewHolder.getView(R.id.sdv_avatar)).setImageURI(searchUserBean.getAvatar());
        baseViewHolder.setText(R.id.tv_name_and_account,String.format("%s(%s)",searchUserBean.getNickName(),searchUserBean.getLoginId()));
        baseViewHolder.setText(R.id.tv_sex_age,
                searchUserBean.getSex() == 1 ? SEX_MAN + searchUserBean.getAge() : SEX_WOMAN + searchUserBean.getAge()
        );
        baseViewHolder.setBackgroundResource(R.id.tv_sex_age,
                searchUserBean.getSex() == 1 ? R.drawable.bg_tv_sex_man : R.drawable.bg_tv_sex_woman
        );
        baseViewHolder.setText(R.id.tv_description,searchUserBean.getDescription());
    }
}
